﻿namespace Attacher
{
    using System.Collections.Generic;

    using Attacher.VisualStudio;

    using Microsoft.Practices.Unity;

    internal class SelectInstanceWindowViewModelFactory : ISelectInstanceWindowViewModelFactory
    {
        #region Attributes

        private readonly IUnityContainer container;

        #endregion

        #region Public Methods

        public SelectInstanceWindowViewModelFactory(IUnityContainer container)
        {
            ParameterChecker.IsNotNull(container, "container");

            this.container = container;
        }

        public SelectInstanceWindowViewModel Create(IEnumerable<VisualStudioInstance> instances)
        {
            ParameterChecker.IsNotNull(instances, "instances");

            SelectInstanceWindowViewModel result = this.container.Resolve<SelectInstanceWindowViewModel>();

            foreach (VisualStudioInstance visualStudioInstance in instances)
            {
                result.Instances.Add(new VisualStudioInstanceViewModel(visualStudioInstance));
            }

            result.SelectedInstance = result.Instances[0];

            return result;
        }

        #endregion
    }
}